package com.yang.jdbc01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author yangjiming
 * @create 2021-03-26 19:39
 */
public class SelectMysql01 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");

        String url="jdbc:mysql://master:3306/shujia";
        String username="root";
        String password="123456";
        Connection conn = DriverManager.getConnection(url, username, password);

        Statement statement = conn.createStatement();
        int age = 20;
        String sql = "select * from student where age = "+age;
        ResultSet rs = statement.executeQuery(sql);

        while(rs.next()){
            int id = rs.getInt("id");
            String name = rs.getString("name");
            int age1 = rs.getInt("age");
            String sex= rs.getString("sex");
            System.out.println(id+"---"+name+"---"+age+"---"+sex);
        }

        rs.close();
        statement.close();
        conn.close();

    }
}
